#ifndef CHECKMEDEVICE_H
#define CHECKMEDEVICE_H

#include <QObject>
#include <QThread>
#include "controller/xdumper2.h"

class checkmeDevice : public QObject
{
    Q_OBJECT
public:
    explicit checkmeDevice(QObject *parent = 0);
    ~checkmeDevice();

    checkmeDevice(const QString &name)
    {
        this->name = name;
    }

    checkmeDevice(xDumper2 dumper)
    {
        name = QString("Checkme_" + QLatin1String(dumper.deviceInfo.sn));
        serialNumber = QString(QLatin1String(dumper.deviceInfo.sn));
        sofewaveVision = QString("V%1.%2").arg(dumper.deviceInfo.app_ver >> 16 & 0xff).arg(dumper.deviceInfo.app_ver >> 8 & 0xff);
        xdumper = dumper;
    }

    checkmeDevice(const checkmeDevice& device)
    {
//        *this = device;
        name = device.name;
        serialNumber = device.serialNumber;
        sofewaveVision= device.sofewaveVision;
        xdumper = device.xdumper;
    }

    checkmeDevice& operator = (const checkmeDevice& device)
    {
        this->name = device.name;
        this->sofewaveVision = device.sofewaveVision;
        this->serialNumber = device.serialNumber;
        return *this;
    }

    bool operator == (const checkmeDevice& device) const
    {
        bool ret = true;
        if(this->name != device.name)
            ret = false;
        if(this->sofewaveVision != device.sofewaveVision)
            ret = false;
        if(this->serialNumber != device.serialNumber)
            ret = false;
        return ret;
    }
    bool operator != (const checkmeDevice& device) const
    {
        bool ret = true;
        if(this->name == device.name)
            ret = false;
        if(this->sofewaveVision == device.sofewaveVision)
            ret = false;
        if(this->serialNumber == device.serialNumber)
            ret = false;
        return ret;
    }

    QString name;
    QString sofewaveVision;
    QString serialNumber;
    xDumper2 xdumper;


    enum StateType{
        OFFLINE = 0,
        ONLINE,
        DOWNLOADING,
    };

    void initFormXdumper(){
        name = QString("Checkme_" + QLatin1String(xdumper.deviceInfo.sn));
        serialNumber = QString(QLatin1String(xdumper.deviceInfo.sn));
        sofewaveVision = QString("V%1.%2").arg(xdumper.deviceInfo.app_ver >> 16 & 0xff).arg(xdumper.deviceInfo.app_ver >> 8 & 0xff);
    }

    StateType connectDevice();
    StateType pingDevice();
    StateType disconnectDevice();
    int getFileList();
    int getFile();


    static QStringList fileNameList;
    static int __stdcall listItemCallback(int cmd, int idx, const char *item, void *arglist);

private:
    StateType deviceState;

signals:

public slots:
    void downloadAllFile();
private:
};

Q_DECLARE_METATYPE(checkmeDevice)
Q_DECLARE_METATYPE(QList<xDumper2>)

#endif // CHECKMEDEVICE_H
